﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsServerSolutions.Wizards;

namespace TV4Home.Server.Vail.AddIn.Wizards.UninstallTVServer
{
    public partial class UninstallTVServerWizard : WizardForm
    {
        public UninstallTVServerWizard()
        {
            InitializeComponent();

            this.WizardTitle = "Uninstall MediaPortal TV Server";
            this.WizardIcon = Properties.Resources.SetupTv;
        }

        #region WPUninstallStart
        private void wpUninstallStart_PageInitializing(object sender, EventArgs e)
        {
            wpUninstallStart.UninstallationTypeButtonClicked += (sender2, e2) =>
                                                                    {
                                                                        this.WizardNextButton.Enabled = true;
                                                                        this.WizardNextButton.PerformClick();
                                                                    };
        }

        private void wpUninstallStart_PageEnter(object sender, EventArgs e)
        {
            this.WizardNextButton.Enabled = false;
        }
        #endregion

        #region WPUninstallation
        private void wpUninstallation_PageEnter(object sender, EventArgs e)
        {
            this.WizardNextButton.Text = "Uninstall";
        }

        private void wpUninstallation_GettingNextPage(object sender, GettingTargetPageEventArgs e)
        {
            bool uninstallSuccessful;

            // disable all buttons
            this.EnableButtons(false, false, false);
            this.CloseDisabled = true;

            uninstallSuccessful = wpUninstallation.UninstallComponents(wpUninstallStart.SelectedUninstallationType == WPUninstallStartControl.UninstallationType.Standard);

            this.CloseDisabled = false;

            if (uninstallSuccessful)
                e.TargetPage = wpFinished;
            else
                e.TargetPage = wpFinishedError;
        }
        #endregion

        #region WPFinished
        private void wpFinished_PageEnter(object sender, EventArgs e)
        {
            this.SetButtonsVisibility(true, false, true);
            this.EnableButtons(false, false, true);
            this.WizardCancelButton.Text = "Done";
        }
        #endregion

        #region WPFinishedError
        private void wpFinishedError_PageEnter(object sender, EventArgs e)
        {
            this.SetButtonsVisibility(true, false, true);
            this.EnableButtons(false, false, true);
            this.WizardCancelButton.Text = "Done";
        }
        #endregion
    }
}
